
import os
img_dir='/home/liuqimin/第6章'
for f in os.listdir(img_dir):
    x=f.find('-')
    if x>2 or x==-1:
        continue

    file1=f[:x]+'.'+ f[x+1:]

    os.rename(f, file1)


ch=Chapter.objects.get(id=356)
book=Book.objects.get(id=5)
tis=Ti.objects.filter(book=book, chapter=ch, ti_number=3)

i=0
for item in tis:
    i = i + 1
    print(tis.count())
    if i<tis.count():
        item.delete()
    else:
        item.qa='liuqimintest2'
        item.save()

    #item.save()

import os
path='D:\\松鼠搜题\\最终版\\高等代数-第四版-北大-王萼芳 石生明\\data'
for item in os.listdir(path):
    if not '.png' in item:
        continue
    if '11.1-' in item:
        src = os.path.join(path, item)
        dst= src.replace('11.1-', '11-')
        os.rename(src, dst)



import os
import re

path='C:\\Users\\liuqimin\\Desktop\\长大高等数学练习册'

for dir0 in os.listdir(path):
    chapter = re.findall(r'第(.{1,2})章', dir0)[0].zfill(3)

    for f in os.listdir(os.path.join(path, dir0)):
        src=os.path.join(path, dir0, f)
        dst=os.path.join(path,chapter+'.'+f.zfill(7))
        os.system('copy "' +src +'"' +'  "'+ dst +'"')


